package com.tadpole.music.view.activity.question;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.tadpole.music.R;
import com.tadpole.music.utils.Mutils;
import com.tadpole.music.utils.NoDoubleClickListener;
import com.tadpole.music.utils.ToastUtils;
import com.tadpole.music.view.activity.base.BaseActivity;
import com.tadpole.music.view.activity.study.MyExamsActivity;
import com.white.progressview.HorizontalProgressView;

import java.text.DecimalFormat;

/**
 * 答题结果
 * Created By 孙岩
 * on 2020/9/25
 */
public class AnswerResultActivity extends BaseActivity {
    //回退
    private View view_back_icon;
    //标题
    private TextView actionbar_title;
    //分数
    private TextView tvScore;
    //状态
    private TextView tvState;
    //答题时间
    private TextView tvTime;
    //选择题
    private LinearLayout llSelect;
    //选择题
    private TextView tvSelect;
    private HorizontalProgressView psSelect;
    //乐理
    private LinearLayout llYueLi;
    //乐理
    private TextView tvYueLi;
    //乐理
    private HorizontalProgressView psYueLi;
    //听辨
    private LinearLayout llTingBian;
    //听辨
    private TextView tvTingBian;
    //听辨
    private HorizontalProgressView psTingBian;
    //音乐常识
    private LinearLayout llChangShi;
    //音乐常识
    private TextView tvChangShi;
    //音乐常识
    private HorizontalProgressView psChangShi;
    //模唱
    private LinearLayout llMoChang;
    //模唱
    private TextView tvMoChang;
    //模唱
    private HorizontalProgressView psMoChang;
    //视唱
    private LinearLayout llShiChang;
    //视唱
    private TextView tvShiChang;
    //视唱
    private HorizontalProgressView psShiChang;

    //重新测试
    private TextView tvAgain;
    //我的考试
    private TextView tvMyExamination;

    //院校id
    private String college_id;
    //等级id
    private String rank_id;
    //常识
    private int chang;
    //模唱
    private int mo;
    //视唱
    private int shi;
    //总分
    private double score;
    //乐理
    private double yue;

    //时间
    private String time;

    //base //只有民管才会有
    private int base;

    private double yin;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_answer_result);

        college_id = getIntent().getStringExtra("college_id");
        rank_id = getIntent().getStringExtra("rank_id");
        time = getIntent().getStringExtra("time");
        chang = getIntent().getIntExtra("chang", 0);
        mo = getIntent().getIntExtra("mo", 0);
        shi = getIntent().getIntExtra("shi", 0);
        score = getIntent().getDoubleExtra("score", 0.0);
        yue = getIntent().getDoubleExtra("yue", 0.0);
        base = getIntent().getIntExtra("base", 0);
        yin = getIntent().getDoubleExtra("yin", 0.0);

        initViews();
        initListeners();
        initData();
    }

    //初始化控件
    private void initViews() {
        view_back_icon = findViewById(R.id.view_back_icon);
        actionbar_title = findViewById(R.id.actionbar_title);
        actionbar_title.setText("答题结果");
        tvScore = findViewById(R.id.tvScore);
        tvState = findViewById(R.id.tvState);
        tvTime = findViewById(R.id.tvTime);
        llYueLi = findViewById(R.id.llYueLi);
        tvYueLi = findViewById(R.id.tvYueLi);
        psYueLi = findViewById(R.id.psYueLi);
        llChangShi = findViewById(R.id.llChangShi);
        tvChangShi = findViewById(R.id.tvChangShi);
        psChangShi = findViewById(R.id.psChangShi);
        llMoChang = findViewById(R.id.llMoChang);
        tvMoChang = findViewById(R.id.tvMoChang);
        psMoChang = findViewById(R.id.psMoChang);
        llShiChang = findViewById(R.id.llShiChang);
        tvShiChang = findViewById(R.id.tvShiChang);
        psShiChang = findViewById(R.id.psShiChang);
        tvAgain = findViewById(R.id.tvAgain);
        tvMyExamination = findViewById(R.id.tvMyExamination);
        llSelect = findViewById(R.id.llSelect);
        tvSelect = findViewById(R.id.tvSelect);
        psSelect = findViewById(R.id.psSelect);
        llTingBian = findViewById(R.id.llTingBian);
        tvTingBian = findViewById(R.id.tvTingBian);
        psTingBian = findViewById(R.id.psTingBian);
    }

    //初始化监听
    private void initListeners() {
        view_back_icon.setOnClickListener(new NoDoubleClickListener() {
            @Override
            protected void onNoDoubleClick(View v) {
                AnswerResultActivity.this.finish();
            }
        });

        tvMyExamination.setOnClickListener(new NoDoubleClickListener() {
            @Override
            protected void onNoDoubleClick(View v) {
                if (Mutils.isNetworkAvailable()) {
                    Intent intent = new Intent(AnswerResultActivity.this, MyExamsActivity.class);
                    startActivity(intent);
                } else {
                    ToastUtils.show("请检查您的网络设置");
                }
            }
        });

        //重新测试
        tvAgain.setOnClickListener(new NoDoubleClickListener() {
            @Override
            protected void onNoDoubleClick(View v) {
                if (Mutils.isNetworkAvailable()) {
                    Intent intent = new Intent(AnswerResultActivity.this, RealAnswerActivity.class);
                    intent.putExtra("college_id", college_id);
                    intent.putExtra("rank_id", rank_id);
                    startActivity(intent);
                    AnswerResultActivity.this.finish();
                } else {
                    ToastUtils.show("请检查您的网络设置");
                }
            }
        });
    }

    //初始化数据
    @SuppressLint("SetTextI18n")
    private void initData() {
        DecimalFormat df = new DecimalFormat("######0"); //四色五入转换成整数

        switch (college_id) {
            case "1": //中央
                llYueLi.setVisibility(View.VISIBLE);
                llChangShi.setVisibility(View.VISIBLE);
                llSelect.setVisibility(View.GONE);
                llShiChang.setVisibility(View.VISIBLE);
                llMoChang.setVisibility(View.VISIBLE);
                llTingBian.setVisibility(View.VISIBLE);

                psYueLi.setProgress(Integer.parseInt(df.format(yue * 100 / 44)));

                tvYueLi.setText("乐理：" + yue + "分");
                break;
            case "2": //中国
            case "5": //武汉
            case "4": //社会艺术
                llYueLi.setVisibility(View.GONE);
                llChangShi.setVisibility(View.GONE);
                llSelect.setVisibility(View.GONE);
                llShiChang.setVisibility(View.GONE);
                llMoChang.setVisibility(View.GONE);
                llTingBian.setVisibility(View.GONE);
                break;
            case "3": //民管
                llSelect.setVisibility(View.VISIBLE);
                llYueLi.setVisibility(View.GONE);
                llChangShi.setVisibility(View.GONE);
                llShiChang.setVisibility(View.VISIBLE);
                llMoChang.setVisibility(View.VISIBLE);
                llTingBian.setVisibility(View.VISIBLE);
                break;
            case "6": //山西高考
                llChangShi.setVisibility(View.GONE);
                llShiChang.setVisibility(View.GONE);
                llSelect.setVisibility(View.GONE);
                llMoChang.setVisibility(View.GONE);
                llYueLi.setVisibility(View.VISIBLE);
                llTingBian.setVisibility(View.VISIBLE);

                psYueLi.setProgress(Integer.parseInt(df.format(yue)));
                tvYueLi.setText("乐理：" + yue + "分");

                psTingBian.setProgress(Integer.parseInt(df.format(yin)));
                tvTingBian.setText("听辨：" + yin + "分");
                break;
        }

        tvScore.setText(score + "");

        if (score >= 80) {
            tvState.setText("优秀");
        } else if (score >= 60) {
            tvState.setText("及格");
        } else {
            tvState.setText("不及格");
        }

        tvTime.setText("答题时间：" + time + "分钟");

        tvShiChang.setText("视唱：" + shi + "分");

        tvMoChang.setText("模唱：" + mo + "分");

        tvChangShi.setText("音乐常识：" + chang + "分");

        tvSelect.setText("选择题：" + base + "分");

        psShiChang.setProgress(shi * 10);
        psMoChang.setProgress(mo * 10);


        psChangShi.setProgress(chang * 100 / 36);

        psSelect.setProgress(base * 100 / 80);
    }
}
